{% assign data = section.settings %}
{% assign blockId = block_id | default: section.block_id %}

<div class="footer" style="--bg: {{data.bg_color}};--color: {{data.font_color}};">
  <div class="container_wrapper">
    <div class="content mb-5 public_radius box-border md:p-[30px] px-[15px] py-[30px] flex md:gap-x-20 md:gap-y-20 gap-y-10 gap-x-14 flex-wrap">
      {% if data.custom_title != '' or data.custom_image.src != '' or data.custom_detail != '' %}
        <div class="custom_text md:w-1/4 w-full">
          {% if data.custom_title != '' %}
            <div class="menu_title">{{ data.custom_title }}</div>
          {% endif %}
          {% if data.custom_image.src != '' %}
            <div class="custom_image mt-5">
              {% include 'lazy_img',src: data.custom_image.src,alt: data.custom_image.alt,class: 'max-w-full object-cover' %}
            </div>
          {% endif %}
          {% if data.custom_detail != '' %}
            <div class="custom_detail mt-5">{{ data.custom_detail }}</div>
          {% endif %}

          <div class="footer_sns mt-5">
            {% include 'share_link',color:data.font_color,section:data %}
          </div>
        </div>
      {% endif %}

      {% include 'footer_menu', nav_id: data.nav.id %}

      <div class="footer_newsletter md:w-1/3 w-full">
        {% if data.email_title != '' %}
          <div class="menu_title">{{ data.email_title }}</div>
        {% endif %}
        {% if data.email_detail != '' %}
          <div class="email_detail mt-5">{{ data.email_detail }}</div>
        {% endif %}
        <div class="footer_input mt-8 relative">
          <input
            class="bg-transparent"
            type="text"
            placeholder="{{ lang.general.email }}"
            id="block_footer_input_{{block_id}}"
          >
          <div
            class="submit_box public_btn mt-[15px]"
            id="newsletter_btn{{block_id}}"
            style="--btn-color: {{data.btn_color}};--btn-bg: {{data.btn_bg}};"
          >
            {{data.sub_text | default: 'Subscribe'}}
          </div>
        </div>
      </div>

      <div class="footer_currency">
        {% if data.is_currency %}
          {% include 'currency',position: 'top',is_currency_flag: data.is_currency_flag %}
        {% endif %}
        {% if data.copyright != '' %}
          <div class="copyright mt-5 text-xs">{{ data.copyright | parse_variables }}</div>
        {% endif %}
      </div>

    </div>
  </div>
</div>

<script type="text/javascript">
	document.addEventListener("DOMContentLoaded",function(){
	  const blockSubmitNewsletter = moi.throttle(function () {
		var domEmail = "#block_footer_input_{{block_id}}";
		email = $("#block_footer_input_{{block_id}}").val();
		if (email == "") {
		  moi.tooltip({
			placement: "top",
			el: domEmail,
			timer: 5000,
			space: 0,
			content: "{{ lang.general.please_enter_a_valid_email_address }}",
		  });
		  return;
		}
		$isvalidemail =
		  /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(
			email
		  );
		if (!$isvalidemail) {
		  moi.tooltip({
			placement: "top",
			el: domEmail,
			timer: 1000,
			space: 0,
			content: "{{ lang.general.please_enter_a_valid_email_address }}",
		  });
		  return;
		}
		const load = moi.nodeShowLoading(
		  "#newsletter_btn{{block_id}}",
		  "{{ section.settings.buttonColor }}"
		);
		moi.ajax({
		  url: "/module/newsletter",
		  type: "POST",
		  data: JSON.stringify({
			email: email,
		  }),
		  dataType: "json",
		  cache: false,
		  complete: function () {
			load.close();
		  },
		  success: function (res) {
			if (res.data && res.data.data) {
			  if (res.data.new_customer) {
				callback_generate_lead();
			  }
			  moi.message({
				content: `{{ section.settings.newsletterTip }}`,
			  });
			} else {
			  moi.tooltip({
				placement: "top",
				el: domEmail,
				timer: 1000,
				space: 0,
				content: "{{ lang.general.subscribe_failed }}",
			  });
			}
		  },
		  error: function () {
			moi.tooltip({
			  placement: "top",
			  el: domEmail,
			  timer: 1000,
			  space: 0,
			  content: "{{ lang.general.connection_fails_please_retry_refresh }}",
			});
		  },
		});
	  }, 3000);
	  $("#newsletter_btn{{block_id}}").click(function () {
		blockSubmitNewsletter();
	  });
	  $("#block_footer_input_{{block_id}}").on("keydown", function (e) {
		if (e.which === 13) {
		  blockSubmitNewsletter();
		}
	  });
	
		function isMobile(argument) {
			if ($(window).width() < 767) {
				$(".block_footer").find("oem-menu").removeClass("oem-menu-acrive")
			}
		}
		$(window).resize(function() {
			isMobile()
		})
		isMobile()
	});
	</script>

{% schema %}
{
	"tag": "footer",
	"class": "footer",
	"is_global": true,
	"name": {
		"zh_CN": "底部",
		"en_US": "Bottom"
	},
	"max_blocks": "0",
	"settings": [
		{
			"type": "card_header",
			"label": {
				"zh_CN": "菜单导航设置",
				"en_US": "Menu Navigation Settings"
			}
		},
		{
			"type": "card_nav",
			"label": {
				"zh_CN": "选择菜单",
				"en_US": "Select menu"
			},
			"default": {
				"id": "",
				"title": ""
			},
			"id": "nav"
		},
		{
			"type": "card_header",
			"label": {
				"zh_CN": "设置",
				"en_US": "Settings"
			}
		},
		{
			"type": "card_input",
			"label": {
				"zh_CN": "订阅标题",
				"en_US": "Subscription title"
			},
			"id": "email_title",
			"default": "Join us"
		},
		{
			"type": "card_text_editor",
			"label": {
				"zh_CN": "订阅描述",
				"en_US": "Subscription description"
			},
			"id": "email_detail",
			"default": "A short sentence describing what someone will receive by subscribing"
		},
		{
			"type": "card_input",
			"label": {
				"zh_CN": "订阅按钮文字",
				"en_US": "Subscribe button text"
			},
			"id": "sub_text",
			"default": "Join"
		},
		{
			"type": "card_textarea",
			"id": "newsletterTip",
			"label": {
				"zh_CN": "订阅成功文字",
				"en_US": "Subscribe successful text"
			},
			"placeholder": {
				"zh_CN": ""
			},
			"default": "Thank you for joining our mailing list!"
		},
		{
			"type": "card_input",
			"label": {
				"zh_CN": "自定义标题",
				"en_US": "Custom title"
			},
			"id": "custom_title",
			"default": "Optional title"
		},
		{
			"type": "card_image",
			"label": {
				"zh_CN": "自定义图片",
				"en_US": "Custom image"
			},
			"default": {
				"src": "",
				"alt": ""
			},
			"info": {
				"zh_CN": "建议宽度1000px以上，高度自适应",
				"en_US": "Recommended width more than 1000px, height adaptive"
			},
			"id": "custom_image"
		},
		{
			"type": "card_text_editor",
			"label": {
				"zh_CN": "自定义描述",
				"en_US": "Custom description"
			},
			"id": "custom_detail",
			"default": "Share information such as the store's physical address, contact details, opening hours, etc."
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "货币切换",
				"en_US": "Currency switch"
			},
			"id": "is_currency",
			"default": "1"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "货币前展示国旗",
				"en_US": "Display the national flag in front of the currency"
			},
			"id": "is_currency_flag",
			"default": "1"
		},
		{
			"type": "card_text_editor",
			"label": {
				"zh_CN": "版权信息",
				"en_US": "Copyright information"
			},
			"id": "copyright",
			"default": "@{{date_year}} {{storeConfig.name}} {{current_domain}}",
			"info": {
				"zh_CN": "<p><a target='_blank' href='https://oemsaas.yuque.com/staff-sbl3ig/clazyz/exmzohc53i16spuo' style='color:#3590e9'>如何配置？</a></p>"
			}
		},
		{
			"type": "card_header",
			"label": {
				"zh_CN": "颜色设置",
				"en_US": "Color Settings"
			}
		},
		{
			"type": "card_color",
			"label": {
				"zh_CN": "背景颜色",
				"en_US": "Background color"
			},
			"default": "#ffffff",
			"id": "bg_color"
		},
		{
			"type": "card_color",
			"label": {
				"zh_CN": "字体颜色",
				"en_US": "Font color"
			},
			"default": "#1A1A1A",
			"id": "font_color"
		},
		{
			"type": "card_color",
			"label": {
				"zh_CN": "订阅按钮文字颜色",
				"en_US": "Subscribe button text color"
			},
			"default": "#ffffff",
			"id": "btn_color"
		},
		{
			"type": "card_color",
			"label": {
				"zh_CN": "订阅按钮文字颜色",
				"en_US": "Subscribe button text color"
			},
			"default": "#df5641",
			"id": "btn_bg"
		},
		{
			"type": "card_header",
			"label": {
				"zh_CN": "SNS账号",
				"en_US": "SNS account"
			}
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Facebook",
				"en_US": "Facebook"
			},
			"id": "is_facebook"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Twitter",
				"en_US": "Twitter"
			},
			"id": "is_twitter"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Pinterest",
				"en_US": "Pinterest"
			},
			"id": "is_pinterest"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Instagram",
				"en_US": "Instagram"
			},
			"id": "is_instagram"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Snapchat",
				"en_US": "SnaPChat"
			},
			"id": "is_snapchat"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Tiktok",
				"en_US": "Tiktok"
			},
			"id": "is_tiktok"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Tumblr",
				"en_US": "Tumblr"
			},
			"id": "is_tumblr"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Linkedin",
				"en_US": "Linkedin"
			},
			"id": "is_linkedin"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Youtube",
				"en_US": "Youtube"
			},
			"id": "is_youtube"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Vimeo",
				"en_US": "Vimeo"
			},
			"id": "is_vimeo"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "VK",
				"en_US": "VK"
			},
			"id": "is_vk"
		},
		{
			"type": "card_switch",
			"label": {
				"zh_CN": "Whatsapp",
				"en_US": "Whatsapp"
			},
			"id": "is_whatsapp"
		}
	],
	"blocks": [],
	"default": {
		"settings": {
			"nav": {
				"id": "",
				"title": ""
			},
			"email_title": "Newsletter",
			"email_detail": "Subscribe to our newsletter and receive special offers",
			"sub_text": "Subscribe",
			"custom_title": "Optional title",
			"custom_image": {
				"src": "",
				"alt": ""
			},
			"custom_detail": "Share information such as the store's physical address, contact details, opening hours, etc.",
			"newsletterTip": "Thank you for joining our mailing list!",
			"bg_color": "#141414",
			"font_color": "#ffffff",
			"btn_color": "#ffffff",
			"btn_bg": "#df5641",
			"copyright": "@{{ date_year }}{{ storeConfig.name }}{{ current_domain }}",
			"is_currency": true,
			"is_currency_flag": false,
			"is_facebook": true,
			"is_twitter": true,
			"is_pinterest": true,
			"is_instagram": true,
			"is_snapchat": true,
			"is_tiktok": false,
			"is_tumblr": false,
			"is_linkedin": false,
			"is_youtube": false,
			"is_vimeo": false,
			"is_vk": false,
			"is_whatsapp": false
		},
		"blocks": []
	}
}
{% endschema %}
